package com.example.demo.model;

import com.example.demo.demos.book.enums.ResultCode;
import lombok.Data;

@Data
public class Result <T>{
    /*业务状态码*/
    private ResultCode code;       //0-成功 ，-1失败    -2未登录
    private String errMsg;
    /*数据*/
    //假如说使用范型
    //private T data;

    private Object data;
    //public static <T> Result<T>success(T data)
    public static Result success(Object data){
        Result result=new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }
//    public  static <T> Result<T> dail( String errMsg)
    public  static Result fail(String errMsg){
        Result result=new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }
    //    public  static <T> Result<T> dail(参数保持不变)
    public  static Result fail(String errMsg,Object data){
        Result result=new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
    ////    public  static <T> Result<T>unlogin()
    public   static Result unlogin(){
        Result result=new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
